const { exec } = require('../db/index')
class UsersService {
  async page({ page, size }) {
    if (page && size) {
      const total = await exec(`select count(id) as num from users`)
      const data = await exec(`select * from users limit ? offset ?`,
        [size * 1, page * size]
      )
      return { err_code: 0, msg: 'success', data, total: total[0].num };
    } else {
      const data = await exec(`select * from users`)
      return { err_code: 0, msg: 'success', data };
    }
  }
}

module.exports = new UsersService